package com.welsmann.app.start.spider.dao;

import java.util.List;

import com.welsmann.app.start.spider.dao.helper.QueryHelper;
import com.welsmann.app.start.spider.entity.News;

/**
 * 新闻实体操作类
 * 
 * @author Welsmann
 * 
 */
public class NewsDAO {

	/**
	 * 获取所有
	 * 
	 * @return
	 */
	public static List<News> findAll() {
		return QueryHelper.list(News.class, "select * from news", null);
	}

	/**
	 * 根据主键获取
	 * 
	 * @param id
	 * @return
	 */
	public static News find(String id) {
		return QueryHelper.single(News.class,
				"select * from news where id = ?", id);
	}

	/**
	 * 新增
	 * 
	 * @param nt
	 * @return
	 */
	public static int insert(News nt) {
		return QueryHelper.update("insert into news values(?,?)", nt.getId(),
				nt.getContent());
	}

	/**
	 * 更新
	 * 
	 * @param nt
	 * @return
	 */
	public static int update(News nt) {
		return QueryHelper.update("update news set content = ? where id = ?",
				nt.getContent(), nt.getId());
	}

	/**
	 * 对象删除
	 * 
	 * @param nt
	 * @return
	 */
	public static int delete(News nt) {
		return QueryHelper
				.update("delete from news where id  = ? ", nt.getId());
	}

	/**
	 * 对象删除
	 * 
	 * @param id
	 * @return
	 */
	public static int delete(String id) {
		return QueryHelper.update("delete from news where id  = ? ", id);
	}

}
